using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using Utility;
using Entities;

public partial class Admin_Themdiadanh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loaddropdownlist();
        }
    }
    private void loaddropdownlist()
    {
        dr_tenddiem.DataSource = tbDiadiemBUS .GetAll();
        dr_tenddiem.DataTextField = tbDiadiemCollumn .tendiadiem .ToString();
        dr_tenddiem.DataValueField = tbDiadiemCollumn .madiadiem .ToString();
        dr_tenddiem.DataBind();
        dr_tenddiem.Items.Insert(0, new ListItem("All", "0"));
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
        //try
        //{
            tbDiadanh  ddanh = new tbDiadanh ();
            ddanh .Tendiadanh  = txttenddanh.Text;
           ddanh.Madiadiem = int.Parse(dr_tenddiem.SelectedValue);
          
            ddanh .Motadiadanh  = txt_mota.Text;

            if (img_ddanh.HasFile)
            {
                string filename = DateTime.Now.Ticks.ToString() + "_" + img_ddanh.FileName;
                img_ddanh.SaveAs(Server.MapPath("~/Hinhanh/" + filename));
                System.Drawing.Image img = System.Drawing.Image.FromFile(
                    Server.MapPath("~/Hinhanh/" + filename));
                ImageUtility.MakeThumbnailPhoto(
                    img, 100, 100, Server.MapPath("~/Hinhanh/Hinh/"), filename);
                ddanh .Hinhdiadanh  = filename;
            }
            else
            {
                ddanh .Hinhdiadanh  = "no_images.jpg";
            }
            tbDiadanhBUS .Insert(ddanh );

            Response.Redirect("~/Admin/Danhsachdiadanh.aspx");
        //}
        //catch
        //{
        //    Response.Redirect("~/Admin/D_Sanphamdoanhnghiep.aspx?id=" + mdn.ToString());
        //}
    }
    }

